import getSysConf from "../../../public/functions/getSysConf";

export default class ListAction {
    constructor(comp) {
        this.comp = comp;
    }

    onBtnOperation = () => {

    }

    handlePageIndexChange = (pageIndex) => {
        const {dispatch, myLeave} = this.comp.props
        let pageInfo = myLeave.activeTab + 'PageInfo'
        dispatch({
            type: 'myLeave/update',
            payload: {
                [pageInfo]: Object.assign({}, myLeave[pageInfo], {
                    pageIndex
                })
            }
        })
        this.queryListAction()
    }

    handlePageSizeChange = (pageSize) => {
        const {dispatch, myLeave} = this.comp.props
        let pageInfo = myLeave.activeTab + 'PageInfo'
        dispatch({
            type: 'myLeave/update',
            payload: {
                [pageInfo]: Object.assign({}, myLeave[pageInfo], {
                    pageSize
                })
            }
        })
        this.queryListAction()
    }

    queryListAction = () => {
        const {dispatch, myLeave, editTable} = this.comp.props;
        const {beginValue, endValue} = myLeave;
        let tableCode = myLeave.activeTab + '_list';
        dispatch({
            type: 'myLeave/queryListAction',
            payload: {
                key: myLeave.activeTab,
                beginDate: beginValue,
                endDate: endValue
            }
        }).then(res => {
            if (res.success) {
                if (res.data) {
                    editTable.setTableData(tableCode, res.data[tableCode]);
                    dispatch({
                        type: 'myLeave/update',
                        payload: {
                            [myLeave.activeTab + 'PageInfo']: res.data[tableCode].pageInfo
                        }
                    })
                }
            }
        })
    }
    /**
     * @desc: record(行数据) ，index(当前index) props, e (事件对象)
     * @param {type}
     * @return:
     */
    onRowDoubleClick = (record, index, props, eve) => {
        const {dispatch, myLeave, form, renderItem} = this.comp.props;
        let minTime = '';
        let formCode = myLeave.activeTab + '_card';
        const {setFormStatus, setAllFormValue, setItemsVisible, EmptyAllFormValue, setFormItemsValue} = form;
        EmptyAllFormValue(formCode);
        setFormStatus(formCode, 'browse');
        setAllFormValue({
            [formCode]: {
                rows: [record]
            }
        })
        dispatch({
            type: 'myLeave/update',
            payload: {
                showMode: 'card',
                isEdit: false,
                minTime,
                billId: record.values['pk_' + myLeave.activeTab].value,
                headerTitle: myLeave.subTitle,
                approvestatus: record.values['approvestatus'] && record.values['approvestatus'].value
            }
        })
    }

    didMount = () => {
        this.getSysConf();
    }

    getSysConf = async () => {
        const {myLeave, dispatch} = this.comp.props;
        const {outsidePageInfo} = myLeave
        let pageSize = await getSysConf();

        dispatch({
            type: 'myLeave/update',
            payload: {
                outsidePageInfo: {
                    ...outsidePageInfo,
                    pageSize: pageSize
                }
            }
        })
        this.queryListAction()
    }
}